import Request from './Request';

/**抽象处理者接口*/
abstract class Handler{
  role:string;
  protected successor:Handler;
  setSuccessor(successor:Handler){
    this.successor = successor;
  }
  abstract handleRequest(request:Request):void;
}

/**主管*/
class Director extends Handler{
  constructor(){
    super();
    this.role = '主管';
  }
  handleRequest(req:Request){
    if(req.value < 10){
      req.done(this);
    }else{
      this.successor.handleRequest(req);
    }
  }
}
/**董事会*/
class Congress extends Handler{
  constructor(){
    super();
    this.role = '董事会';
  }
  handleRequest(req:Request){
    req.done(this);
  }
}
/**董事长*/
class President extends Handler{
  constructor(){
    super();
    this.role = '总裁';
  }
  handleRequest(req:Request){
    if(req.value >= 10 && req.value < 1000){
      req.done(this);
    }else{
      this.successor.handleRequest(req);
    }
  }
}

export {Handler, Director, Congress, President};